package com.mybook.app.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Created by zfh on 1/11/17.
 */
public class JsonUtil {
    // TODO
    public static String toJsonString(Object obj) {
        try {
            return new ObjectMapper().writeValueAsString(obj);
        } catch (Exception e) {
            Logger.warn(JsonUtil.class, "转化异常", e);
        }
        return null;
    }

    public static <T> T toObject(Class<T> cls, String json) {
        try {
            return new ObjectMapper().readValue(json, cls);
        } catch (Exception e) {
            Logger.warn(JsonUtil.class, "转化异常", e);
        }
        return null;
    }
}
